package com.atguigu.cloud.exp;

import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.resp.ReturnCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * ClassName:GlobalExceptionHandler
 * Package:com.atguigu.cloud.exp
 * Description: 描述信息
 *
 * @date:2024/2/29 15:17
 * @author:坤坤
 */
@Slf4j
//@RestControllerAdvice//控制器通知
public class GlobalExceptionHandler
{
    /**
     * 默认全局异常处理。
     * @param e the e
     * @return ResultData
     */
    @ExceptionHandler(RuntimeException.class)//捕获运行时异常
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//响应码为500的
    public ResultData<String> exception(Exception e) {
        System.out.println("----come in GlobalExceptionHandler");
        log.error("全局异常信息exception:{}", e.getMessage(), e);
        return ResultData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());
    }
}